package com.carp.exception;


import com.carp.common.DBResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 如果抛出ServiceException,调用此方法
     */
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public DBResult handle(ServiceException se){
        return DBResult.error(se.getCode(), se.getMessage());
    }
}
